//################################
// 版权所有：鸽子游戏俱乐部
// 系统名称：鸽子游戏俱乐部-移动版
// 文件名称：GZGAMEApp.js
// 创建时间：2017年04月08日
// 创建人员：Lemo
// 功能说明：应用主入口
//################################

'use strict';

import React, { Component } from 'react';
import {
    StyleSheet,
    Navigator,
    BackAndroid,
    AppState,
    View,
    StatusBar,
    Platform,
    Text,
    Dimensions,
    Image,
} from 'react-native';

import PubSub from 'pubsub-js';
import Orientation from 'react-native-orientation';

import {
    Routes,
    PubSubTopics,
    CommonData,
    UIConstants,
    Colors,
} from './common';

import SplashContainer from './login/containers/splashContainer';

import ToastModal from './components/toastModal';
import SpinkitModal from './components/spinkitModal';

const WINDOW_WIDTH = Dimensions.get('window').width;
const WINDOW_HEIGHT = Dimensions.get('window').height;

var _navigator, _route;

class GZGAMEApp extends Component {
    constructor(props) {
        super(props);

        this.renderScene = this.renderScene.bind(this);
        this.configureScene = this.configureScene.bind(this);
        this.onDidFocus = this.onDidFocus.bind(this);
        this.statusBarStyle = Platform.OS == 'ios' ? 'light-content' : 'default';
    }

    componentDidMount() {
        Orientation.lockToPortrait();
    }
    
    onDidFocus(route) {
        CommonData.currentNavigator=this.navigatorRoot?this.navigatorRoot:null;
        CommonData.currentRoute = route;
        var routeName = route.name;
        switch (routeName) {
            case Routes.MAIN:
                PubSub.publish(PubSubTopics.MAIN_ONDIDFOCUS);
			case Routes.MY_RESETPWD:
                PubSub.publish(PubSubTopics.MY_RESET_PWD);
				break;
            default:
                break;
        }
    }

    configureScene(route, routeStack) {
        if (route.friend) {
            return Navigator.SceneConfigs.HorizontalSwipeJump;
        } else {
            return Navigator.SceneConfigs.FadeAndroid;
        }
    }

    renderScene(route, navigator) {
        let Component = route.component;
        _navigator = navigator;
        _route = route;
        
        return (
            <Component navigatorRoot={navigator} route={route} />
        );
    }

    render() {
        return (
            <View style={{flex: 1}}>
                <StatusBar
                    translucent={true}
                    backgroundColor={'transparent'}
                    barStyle={this.statusBarStyle}
                    hidden={true}
                    animated={true}
                    />
                <Navigator
                    ref={(ref) => {this.navigatorRoot = ref}}
                    style={styles.navigator}
                    configureScene={this.configureScene}
                    renderScene={this.renderScene}
                    initialRoute={{
                        name:Routes.SPLASH,
                        component:SplashContainer,    
                    }}
                    onDidFocus={this.onDidFocus}
                />
                <ToastModal />
                <SpinkitModal />
            </View>
        );
    }
}

const styles = StyleSheet.create({
    navigator: {
        flex: 1,
    },
});

export default GZGAMEApp;